home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / game / shoot / ADoom_src_1_2.lha / ADoom_src / amiga_fixed.s < prev    next >
Text File  |  1998-03-12  |  3KB  |  166 lines

  1.         mc68020
  2.         fpu
  3.  
  4. ;-----------------------------------------------------------------------
  5.         xdef    _FixedMul
  6.         xdef    @FixedMul_040
  7.         xdef    @FixedMul_060fpu
  8.         xdef    @FixedMul_060
  9.         xdef    _FixedDiv
  10.         xdef    @FixedDiv_040
  11.         xdef    @FixedDiv_060fpu
  12.         xdef    @SetFPMode
  13.  
  14.         section    text,code
  15.  
  16. ;-----------------------------------------------------------------------
  17. ; set 68060 FPU rounding mode to "truncate towards minus infinity"
  18. ; otherwise demos get out of step and play wrong
  19.  
  20.         cnop    0,4
  21.  
  22. @SetFPMode    fmove.l    fpcr,d0
  23.         or.b    #$20,d0
  24.         and.b    #~$10,d0
  25.         fmove.l    d0,fpcr
  26.         rts
  27.  
  28. ;-----------------------------------------------------------------------
  29.         cnop    0,4
  30.  
  31. ; fixed_t FixedMul (fixed_t a, fixed_t b)
  32.  
  33. @FixedMul_040    muls.l    d1,d1:d0
  34.         move.w    d1,d0
  35.         swap    d0
  36.         rts
  37.  
  38. ;-----------------------------------------------------------------------
  39.         cnop    0,4
  40.  
  41. ; special version for 68060 which otherwise traps and emulates 64-bit muls.l
  42.  
  43. @FixedMul_060fpu
  44.         fmove.l    d0,fp0
  45.         fmul.l    d1,fp0
  46.         fmul.s    #0.0000152587890625,fp0    ; d0 * d1 / 65536 (* reciprocal)
  47.         fmove.l    fp0,d0
  48.         rts
  49.  
  50. ;-----------------------------------------------------------------------
  51.         cnop    0,4
  52.  
  53. ; I'm told all Amiga 68060 accelerators have FPUs, but just in case...
  54.  
  55. @FixedMul_060    movem.l d2-d5,-(sp)
  56.  
  57.         clr.b    d5          ; clear sign tag
  58.         tst.l    d0          ; multiplier negative?
  59.         bge    .not1
  60.         neg.l    d0
  61.         or.b    #1,d5
  62. .not1
  63.         tst.l    d1          ; multiplicand negative?
  64.         bge    .not2
  65.         neg.l    d1
  66.         eor.b    #1,d5
  67. .not2
  68.         move.l    d0,d2       ; mr
  69.         move.l    d0,d3       ; mr
  70.         move.l    d1,d4       ; md
  71.         swap    d3          ; hi_mr in lo d3
  72.         swap    d4          ; hi_md in lo d4
  73.  
  74.         mulu.w    d1,d0       ; [1] lo_mr * lo_md
  75.         mulu.w    d3,d1       ; [2] hi_mr * lo_md
  76.         mulu.w    d4,d2       ; [3] lo_mr * hi_md
  77.         mulu.w    d4,d3       ; [4] hi_mr * hi_md
  78.  
  79.         clr.l    d4
  80.         swap    d0
  81.         add.w    d1,d0
  82.         addx.l    d4,d3
  83.         add.w    d2,d0
  84.         addx.l    d4,d3
  85.         swap    d0
  86.  
  87.         clr.w    d1
  88.         clr.w    d2
  89.  
  90.         swap    d1
  91.         swap    d2
  92.         add.l    d2,d1
  93.         add.l    d3,d1
  94.  
  95.         tst.b    d5          ; check sign of result
  96.         beq    .skip
  97.  
  98.         not.l    d0
  99.         not.l    d1
  100.         addq.l    #1,d0
  101.         addx.l    d4,d1
  102.  
  103. .skip
  104.         move.w    d1,d0
  105.         swap    d0
  106.  
  107.         movem.l    (sp)+,d2-d5
  108.         rts
  109.  
  110. ;-----------------------------------------------------------------------
  111.         cnop    0,4
  112.  
  113. ; fixed_t FixedDiv (fixed_t a, fixed_t b)
  114.  
  115. @FixedDiv_040    movem.l    d2/d3,-(sp)
  116.         move.l    d0,d3
  117.         swap    d0
  118.         move.w    d0,d2
  119.         ext.l    d2
  120.         clr.w    d0
  121.         tst.l    d1
  122.         beq.b    3$        ; check for divide by 0 !
  123.         divs.l    d1,d2:d0
  124.         bvc.b    1$
  125. 3$        eor.l    d1,d3
  126.         bmi.b    2$
  127.         move.l    #$7fffffff,d0
  128.         bra.b    1$
  129. 2$        move.l    #$80000000,d0
  130. 1$        movem.l    (sp)+,d2/d3
  131.         rts
  132.  
  133. ;-----------------------------------------------------------------------
  134.         cnop    0,4
  135.  
  136. ; m68060fpu fixed division
  137.  
  138. @FixedDiv_060fpu
  139.         tst.l    d1
  140.         beq.b    3$        ; check for divide by 0 !
  141.         fmove.l    d0,fp0
  142.         fmove.l    d1,fp1
  143.         fdiv.x    fp1,fp0
  144.         fmul.s    #65536.0,fp0
  145.         fmove.l    fp0,d0
  146.         rts
  147.  
  148. 3$        eor.l    d1,d0
  149.         bmi.b    2$
  150.         move.l    #$7fffffff,d0
  151.         rts
  152.  
  153. 2$        move.l    #$80000000,d0
  154.         rts
  155.  
  156. ;-----------------------------------------------------------------------
  157.         section    __MERGED,bss
  158.  
  159. ; pointers to CPU-specific FixedMul and FixedDiv routine
  160.  
  161. _FixedMul    ds.l    1
  162. _FixedDiv    ds.l    1
  163.  
  164. ;-----------------------------------------------------------------------
  165.         end
  166.